import 'package:flutter/material.dart';
import 'package:ljy_flutter/change_notifier_proxy_privoder_ex/models/book_manger_model.dart';
import 'package:ljy_flutter/change_notifier_proxy_privoder_ex/models/book_model.dart';
import 'package:provider/provider.dart';

class BookButton extends StatelessWidget {
  final Book book;

  const BookButton({super.key, required this.book});

  @override
  Widget build(BuildContext context) {
    var bookManagerModel = Provider.of<BookMangerModel>(context);
    final isContain = bookManagerModel.books.contains(book);

    return GestureDetector(
      onTap:
          isContain
              ? () => bookManagerModel.removeFaves(book)
              : () => bookManagerModel.addFaves(book),
      child: SizedBox(
        width: 100,
        height: 100,
        child:
            isContain
                ? Icon(Icons.star, color: Colors.red)
                : Icon(Icons.star_border),
      ),
    );
  }
}
